package model;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 
 * @author christopher
 * This is the Statistics class. It encapsulates various data related to
 * players and their statistics, specifically:
 *    - how much time a player has currently spent playing
 *    - how many moves a player has made
 *    - how long the game has been running overall
 */
public class Statistics implements Serializable{
	private static final long serialVersionUID = 3603709400066082110L;

	// how much time a player has currently spent playing
	private HashMap<Player, Double> playerTime = new HashMap<Player, Double>();
	
	// how long the game has been running overall
	private double gameTime;
	
	// how many moves a player has made
	private HashMap<Player, Integer> playerTurns = new HashMap<Player, Integer>();
	
	public Statistics(Player[] players) {
		for(int i = 0; i < 4; i++) {
			playerTime.put(players[i], 0.0);
			playerTurns.put(players[i], 0);
		}
		
		gameTime = 0;
	}
	
	// Add a turn to the turncounter for a player
	public void updateTurnCounter(Player player) {
		int old = playerTurns.get(player);
		playerTurns.put(player, old + 1);
	}
	
	// Add time 
	public void updateTimeCounter(Player player, double time) {
		double old = playerTime.get(player);
		playerTime.put(player, old + time);
	}
	
	// Add a turn to the turncounter for a player
	public int getTurnCounter(Player player) {
		return playerTurns.get(player);
	}
	
	// Add time 
	public double getTimeCounter(Player player, double time) {
		return playerTime.get(player);
	}
}